{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# MTH 9879 Market Microstructure Models,    Spring 2015 \n",
    "\n",
    "## Lecture 4: Understanding the bid-ask spread\n",
    "\n",
    "Tai-Ho Wang    \n",
    "Department of Mathematics   \n",
    "  \n",
    "  \n",
    "<h2><img src=\"http://mfe.baruch.cuny.edu/wp-content/uploads/2014/09/BCCUNYstacked_BLK.jpg\" align = \"center\" width=160></h2>  \n",
    "\n",
    "$$\n",
    "\\newcommand{\\bea}{\\begin{eqnarray}}\n",
    "\\newcommand{\\eea}{\\end{eqnarray}}\n",
    "\\newcommand{\\supp}{\\mathrm{supp}}\n",
    "\\newcommand{\\F}{\\mathcal{F} }\n",
    "\\newcommand{\\cF}{\\mathcal{F} }\n",
    "\\newcommand{\\E}{\\mathbb{E} }\n",
    "\\newcommand{\\Eof}[1]{\\mathbb{E}\\left[ #1 \\right]}\n",
    "\\def\\Cov{{ \\mbox{Cov} }}\n",
    "\\def\\Var{{ \\mbox{Var} }}\n",
    "\\newcommand{\\1}{\\mathbf{1} }\n",
    "\\newcommand{\\p}{\\partial}\n",
    "\\newcommand{\\PP}{\\mathbb{P} }\n",
    "\\newcommand{\\Pof}[1]{\\mathbb{P}\\left[ #1 \\right]}\n",
    "\\newcommand{\\QQ}{\\mathbb{Q} }\n",
    "\\newcommand{\\R}{\\mathbb{R} }\n",
    "\\newcommand{\\DD}{\\mathbb{D} }\n",
    "\\newcommand{\\HH}{\\mathbb{H} }\n",
    "\\newcommand{\\spn}{\\mathrm{span} }\n",
    "\\newcommand{\\cov}{\\mathrm{cov} }\n",
    "\\newcommand{\\HS}{\\mathcal{L}_{\\mathrm{HS}} }\n",
    "\\newcommand{\\Hess}{\\mathrm{Hess} }\n",
    "\\newcommand{\\trace}{\\mathrm{trace} }\n",
    "\\newcommand{\\LL}{\\mathcal{L} }\n",
    "\\newcommand{\\s}{\\mathcal{S} }\n",
    "\\newcommand{\\ee}{\\mathcal{E} }\n",
    "\\newcommand{\\ff}{\\mathcal{F} }\n",
    "\\newcommand{\\hh}{\\mathcal{H} }\n",
    "\\newcommand{\\bb}{\\mathcal{B} }\n",
    "\\newcommand{\\dd}{\\mathcal{D} }\n",
    "\\newcommand{\\g}{\\mathcal{G} }\n",
    "\\newcommand{\\half}{\\frac{1}{2} }\n",
    "\\newcommand{\\T}{\\mathcal{T} }\n",
    "\\newcommand{\\bit}{\\begin{itemize}}\n",
    "\\newcommand{\\eit}{\\end{itemize}}\n",
    "\\newcommand{\\beq}{\\begin{equation}}\n",
    "\\newcommand{\\eeq}{\\end{equation}}\n",
    "\\newcommand{\\tr}{\\mbox{tr}}\n",
    "\\newcommand{\\underbar}{\\underline}\n",
    "$$\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Outline of Lecture 4\n",
    "\n",
    "-   The Roll model\n",
    "\n",
    "-   TAQ data cleaning and trade signing\n",
    "\n",
    "-   A generalization of the Roll model\n",
    "\n",
    "-   The Glosten and Milgrom model\n",
    "\n",
    "-   The Foucault (1999) model\n",
    "\n",
    "-   The Glosten and Harris model\n",
    "\n",
    "-   The Madhavan-Richardson-Roomans model\n",
    "\n",
    "-   The Huang and Stoll model\n",
    "\n",
    "-   PIN - the probability of informed trading\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### The Roll model\n",
    "\n",
    "-   We think of the efficient price\n",
    "    $m_t=\\mathbb{E} [\\tilde S|\\mathcal{F} _t]$ as being the expected\n",
    "    value of the cashflows of a security, conditioning on all public\n",
    "    information.\n",
    "\n",
    "\n",
    "-   We model trade prices $p_t$ as\n",
    "\n",
    "    <a name=\"eq:Roll\"></a>(1)\n",
    "    $$p_t=m_{t}+c\\,\\epsilon_t$$\n",
    "\n",
    "    where (under competition), $c$ is the market maker($\\mathcal{M}$)’s\n",
    "    cost to trade and $\\epsilon_t=\\pm1$ is a trade sign indicator.\n",
    "\n",
    "\n",
    "-   We further assume that trade signs are serially independent with\n",
    "    equal probabilities of buys and sells.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### The Roll model\n",
    "\n",
    "Under these (very unrealistic) assumptions, we have\n",
    "\n",
    "\\begin{eqnarray*}\n",
    "\\gamma_0:=\\mbox{Var}[\\Delta p_t]&=&\\mathbb{E} [\\Delta p_t^2]\\\\\n",
    "&=&\\mathbb{E} [\\Delta m_t^2]+c^2\\,\\mbox{Var}[\\epsilon_t-\\epsilon_{t-1}]\\\\\n",
    "&=&\\sigma^2+2\\,c^2\\end{eqnarray*}\n",
    "\n",
    "where $\\sigma$ is the volatility of the stock per trade.\n",
    "\n",
    "Also,\n",
    "\n",
    "\\begin{eqnarray*}\n",
    "\\gamma_1:&=&\\mbox{Cov}[\\Delta p_{t-1},\\Delta p_t]\\\\\n",
    "&=&\\mathbb{E} [\\Delta p_{t-1}\\,\\Delta p_t]\\\\\n",
    "&=&\\mathbb{E} [\\left\\{\\Delta m_{t-1}+c\\,(\\epsilon_{t-1}-\\epsilon_{t-2})\\right\\}\\left\\{\\Delta m_{t}+c\\,(\\epsilon_{t}-\\epsilon_{t-1})\\right\\}]\\\\\n",
    "&=&-c^2\\end{eqnarray*}\n",
    "\n",
    "Higher order autocovariances are all zero.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### The Roll model\n",
    "\n",
    "We conclude that the effective half-spread is given by\n",
    "$$c=\\sqrt{-\\gamma_1}$$ and $$\\sigma^2=\\gamma_0+2\\,\\gamma_1$$ The first\n",
    "order autocovariance is negative because of bid-ask bounce.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Autocorrelation of BAC price changes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false,
    "slideshow": {
     "slide_type": "-"
    }
   },
   "outputs": [],
   "source": [
    "%load_ext rmagic"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "trying URL 'http://mfe.baruch.cuny.edu/wp-content/uploads/2015/02/tq.zip'\n",
       "Content type 'application/zip' length 695952 bytes (679 Kb)\n",
       "opened URL\n",
       "==================================================\n",
       "downloaded 679 Kb\n",
       "\n",
       "trying URL 'http://mfe.baruch.cuny.edu/wp-content/uploads/2015/02/tqBAC_20130731.zip'\n",
       "Content type 'application/zip' length 105990 bytes (103 Kb)\n",
       "opened URL\n",
       "==================================================\n",
       "downloaded 103 Kb\n",
       "\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%%R\n",
    "download.file(url=\"http://mfe.baruch.cuny.edu/wp-content/uploads/2015/02/tq.zip\", destfile=\"tq.zip\")\n",
    "unzip(zipfile=\"tq.zip\")\n",
    "download.file(url=\"http://mfe.baruch.cuny.edu/wp-content/uploads/2015/02/tqBAC_20130731.zip\", destfile=\"tqBAC_20130731.zip\")\n",
    "unzip(zipfile=\"tqBAC_20130731.zip\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false,
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [],
   "source": [
    "%%R\n",
    "\n",
    "library(xts)\n",
    "library(highfrequency)\n",
    "library(quantmod)\n",
    "\n",
    "load(\"tq.rData\")\n",
    "tqdata <- tqBAC"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 1, 1, 1, 1, 1],\n",
       "       [2, 5, 3, 2, 4, 1],\n",
       "       [2, 1, 2, 2, 2, 3],\n",
       "       [5, 4, 1, 3, 6, 2],\n",
       "       [2, 1, 1, 2, 2, 1],\n",
       "       [2, 1, 1, 1, 1, 2],\n",
       "       [5, 6, 3, 1, 2, 4],\n",
       "       [2, 2, 1, 1, 2, 2],\n",
       "       [6, 5, 4, 1, 3, 2]], dtype=int32)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%R data.frame(head(tqdata))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAeAAAAHgCAIAAADytinCAAAgAElEQVR4nO3de3xU5Z348e/kQghk\nIAkQcgETwECQiNWEKhBiuNRSQPqiIri62nghaNSXglfWrmBttZXbT7da3aCWLa1QrEhAyk0MFDcI\nFDXsmgBySyD3kEAu5jrn98fMTpNxCEHhzHeGz/uvyeGc8zzPycknw2QCFsMwBACgj5+nJwAAcI9A\nA4BSBBoAlCLQAKAUgQYApQg0AChFoAFAKQINAEoRaABQikADgFIEGgCUItAAoBSBBgClCDQAKEWg\nAUApAg0AShFoAFCKQAOAUgQaAJQi0ACgFIEGAKUINAAoRaABQCkCDQBKEWgAUIpAA4BSBBoAlCLQ\nAKAUgQYApQg0AChFoAFAKQINAEoRaABQikADgFIEGgCUItAAoBSBBgClCDQAKEWgAUApAg0AShFo\nAFCKQAOAUgQaAJQi0ACgFIEGAKUINAAoRaABQCkCDQBKEWgAUIpAA4BSBBoAlCLQAKAUgQYApQg0\nAChFoAFAKQINAEoRaABQKsDTE7g4VVVVH3zwgWEYnp4IAIiIBAUF3XnnnYGBgZfj5F72DPrjjz/O\nycnx9CwAwCErK6uwsPAyndzLnkGLyNixYzMyMjw9CwAQEdm7d+/lO7mXPYMGgCsHgQYApUwNtM1m\nO3funM1mM3NQAPBSZgS6sbFx4cKFQ4cODQoK6t27d7du3eLj4xctWtTU1GTC6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ri4uNDQUN9Y49GjR998881NmzZ98MEHzi0+sK68vLxhw4bNnTs3Jyfn2muvXb58ufjE0qKi\non7729/edNNNFoslPDzc/tKNV6/rySefFJEPP/zQucXtcjy4Ru+4jhelurraarXaH/fq1au1tbWu\nrs6zU/o+rFZrRESEYRjr16+/8847X331VYvF4gNrtNlsc+bMWbp0afv/AtgH1iUiZWVlGzZsSEpK\n+uijj6Kjo2fPni0+sbSCgoJf/epXubm59fX1DzzwwL333is+sa723C7Hg2v0wWfQYWFhtbW19se1\ntbX+/v7tfwbljaqqqubMmVNYWPjhhx8mJyeLT6xxxYoV0dHRU6dOraysdG70gXWJSPfu3VNTU+fO\nnSsiixcvDgkJqays9IGlbdiw4Sc/+clNN90kIi+88ELv3r3Pnj3rA+tqz+1yPLhGH3wGPXjwYOdb\nHQoKCuLi4rzlL1xuNTU13XLLLcOHD//ss8/sdRafWOOOHTuys7P79u07dOjQtra2vn377tmzxwfW\nJSIDBw50Prb/y8L+/v4+sLS2tjabzWZ/bCl9hhIAAANwSURBVBhGa2urYRg+sK723C7Hk2s07dVu\n09h/5Prhhx82NDT87Gc/W7hwoadn9L2sXr36uuuuO95Oa2urD6yxsrKyqKioqKjoyy+/9PPzKyoq\namxs9IF1GYbR0NDQp0+f1atXnz179umnnx43bpzhE7dlXl5eaGjozp07a2pq5s2bl5qaavjEumJi\nYlzexeGyHA+u0QcDbRjG3r17R44c2adPn/T09MbGRk9P53t5+umnXb6nVlRUGD60xoqKCue7OAxf\nWdff//73kSNHhoSETJ48+eTJk/aNPrC0NWvWDB06NCQkZOrUqYWFhfaN3r6u9oE2zrMcT62Rf7Af\nAJTy4leLAMC3EWgAUIpAA4BSBBoAlCLQAKAUgQYApQg0AChFoAFAKQINAEoRaABQikADgFIEGgCU\nItAAoBSBBgClCDQAKEWgAUApAg0AShFoAFCKQAOAUgQaPquurs5isVRWVnp6IsB3RKABQCkCjSvO\n73//+wEDBgQHB48ePfrIkSP2je+++25cXFxcXNzKlSvj4uI8OkHAgUDjylJeXv7444//6U9/Kioq\nGjZs2NKlS0UkLy/vmWeeWbt27aeffpqVleXpOQIOBBpXFqvVWlBQcPPNN1ut1ujo6JqaGhFZs2ZN\nenr6qFGjYmJinnrqKU/PEXAI8PQEAFMFBQWtXr06Ozvb398/KCioX79+InL69OlRo0bZd4iNjfXo\nBIF/4hk0rizvv//+X//61/Xr1+/evTs9Pd2+MTIysrCw0P741KlTHpsc0BHPoOHjzp49GxDguM+D\ng4NLS0u7detmsVhyc3NfffXV8PDwtra2mTNnTp06ddasWTExMcuWLfPshAEnnkHDx1199dVh/+eP\nf/zj3XffHRwcHBsbO3/+/BdffPHw4cPvvfdecnLywoULp02blpqampGRYbVaPT1rQIRn0PBhISEh\nhmF8e/vHH3/sfHzixAkROXny5Lhx40pKSkRk3759ERERZs0R6AzPoAE5efLkbbfdVlxc3NzcvHjx\n4smTJ3t6RoAIgQZEJDU19e67777++utjY2O7dev20EMPeXpGgIiIxe3fAQEAHsczaABQikADgFIE\nGgCUItAAoBSBBgClCDQAKEWgAUApAg0AShFoAFCKQAOAUgQaAJQi0ACgFIEGAKUINAAoRaABQKn/\nDwEmQ92B+Yg/AAAAAElFTkSuQmCC\n"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%%R\n",
    "#---------------------------------------------------------------------------\n",
    "# Figure 1: Autocorrelation of BAC price changes\n",
    "p <- as.numeric(tqdata$PRICE)\n",
    "dp <- diff(p)\n",
    "ac <- acf(dp,lag=100,plot=FALSE)\n",
    "plot(ac,col=\"red\",main=NA)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "source": [
    "Figure 1: Autocorrelation of BAC price changes (04-May-2012)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### 5 minutes of BAC trades"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false,
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Error in plot.xts(tqdata$BID[min5], ylim = c(7.7, 7.8), main = NA) : \n",
      "  'x' must be a time-series object\n"
     ]
    }
   ],
   "source": [
    "%%R\n",
    "\n",
    "# 5 minutes of BAC trades\n",
    "min5 <- '2012-05-04 11:50:00::2012-05-04 11:55:00'\n",
    "plot(tqdata$BID[min5],ylim=c(7.7,7.8),main=NA)\n",
    "lines(tqdata$OFR[min5],col=\"red\")\n",
    "points(tqdata$PRICE[min5][tqdata$EX[min5]==\"D\"],col=\"red\",pch=20)\n",
    "points(tqdata$PRICE[min5][tqdata$EX[min5]==\"B\"],col=\"blue\",pch=20)\n",
    "points(tqdata$PRICE[min5][tqdata$EX[min5]==\"Z\"],col=\"orange\",pch=20)\n",
    "points(tqdata$PRICE[min5][tqdata$EX[min5]==\"Y\"],col=\"purple\",pch=20)\n",
    "points(tqdata$PRICE[min5][tqdata$EX[min5]==\"P\"],col=\"dark green\",pch=20)\n",
    "legend(\"topright\", c(\"D - FINRA           \",\n",
    "                     \"B - NASDAQ OMX BX\",\n",
    "                     \"Z - BATS Exchange\",\n",
    "                     \"Y - BATS Y-Exchange\",\n",
    "                     \"P - NYSE Arca SM\"), text.width = strwidth(\"Y - BATS Y-Exchange Y 1,000,000\"),\n",
    "       col=c(\"red\",\"blue\",\"orange\",\"purple\", \"dark green\"), pch=20, inset=0.05)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "-"
    }
   },
   "source": [
    "Figure 2: BAC trades (04-May-2012)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### 10 minutes of BAC trades from a later date"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Error in plot.xts(tqdata$BID[min10], ylim = c(14.72, 14.8), main = NA) : \n",
      "  'x' must be a time-series object\n"
     ]
    }
   ],
   "source": [
    "%%R\n",
    "\n",
    "load(\"tqBAC_20130731.rData\")\n",
    "\n",
    "# The data is a list of xts objects by exchange.  Consolidate into one object\n",
    "tqdata <- NULL\n",
    "for(i in 1:8){tqdata <- rbind(tqdata,tqBAC[[i]])}\n",
    "\n",
    "#---------------------------------------------------------------------------\n",
    "# Figure 3: 10 minutes of BAC trades\n",
    "min10 <- '2013-07-31 11:15:00::2013-07-31 11:25:00'\n",
    "\n",
    "plot(tqdata$BID[min10],ylim=c(14.72,14.80),main=NA)\n",
    "lines(tqdata$OFR[min10],col=\"red\")\n",
    "points(tqdata$PRICE[min10][tqdata$EX[min10]==\"D\"],col=\"red\",cex=1.5,pch=20)\n",
    "points(tqdata$PRICE[min10][tqdata$EX[min10]==\"T\"],col=\"blue\",cex=1.5,pch=20)\n",
    "points(tqdata$PRICE[min10][tqdata$EX[min10]==\"P\"],col=\"pink\",cex=1.5,pch=20)\n",
    "points(tqdata$PRICE[min10][tqdata$EX[min10]==\"Z\"],col=\"orange\",cex=1.5,pch=20)\n",
    "points(tqdata$PRICE[min10][tqdata$EX[min10]==\"Y\"],col=\"purple\",cex=1.5,pch=20)\n",
    "points(tqdata$PRICE[min10][tqdata$EX[min10]==\"K\"],col=\"dark green\",cex=1.5,pch=20)\n",
    "points(tqdata$PRICE[min10][tqdata$EX[min10]==\"B\"],col=\"green\",cex=1.5,pch=20)\n",
    "points(tqdata$PRICE[min10][tqdata$EX[min10]==\"N\"],col=\"brown\",cex=1.5,pch=20)\n",
    "\n",
    "legend(\"topright\", c(\"D - FINRA           \",\n",
    "                     \"T - NASDAQ\",\n",
    "                     \"P - NYSE Arca\",\n",
    "                     \"Z - BATS Exchange\",\n",
    "                     \"Y - BATS Y-Exchange\",\n",
    "                     \"K - DirectEdge X\",\n",
    "                     \"B - NASDAQ BX\",\n",
    "                     \"N - NYSE\"\n",
    "                     ), text.width = strwidth(\"Y - BATS Y-Exchange Y 1,000,000\"),\n",
    "       col=c(\"red\",\"blue\",\"pink\",\"orange\",\"purple\", \"dark green\",\"green\",\"brown\"), cex=1.5, pch=20, inset=0.05)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 3: BAC trades (31-Jul-2013)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Signing trades: The Lee and Ready tick test\n",
    "\n",
    "Lee and Ready devised a simple method to infer trade direction in cases\n",
    "when quote data (and so mid-price) is not available:\n",
    "\n",
    "-   If a trade is on an uptick, it is a buy.\n",
    "\n",
    "-   If the trade is on a downtick, it is a sell.\n",
    "\n",
    "-   If the trade is on a zero-uptick, it is a buy.\n",
    "\n",
    "-   If the trade is on a zero-downtick, it is a sell.\n",
    "\n",
    "It can be verified that this algorithm classifies most trades in the\n",
    "same way as the classification based on comparison with the mid-price.\n",
    "However, note that according to Bandi and Russell “the Lee and Ready\n",
    "method, for example, is known to categorize incorrectly about 15% of the\n",
    "trades”.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Bessembinder recommendation\n",
    "\n",
    "-   If quotes are available, Lee and Ready (1991) recommend comparing\n",
    "    current trade prices with quotes lagged by around 5 seconds.\n",
    "\n",
    "-   Ellis, Michaely, and O’Hara (EMO) assign trades executed at the ask\n",
    "    (bid) quote as buys (sells), while using the tick test for all other\n",
    "    trades.\n",
    "\n",
    "However, [Bessembinder]<sup id=\"cite_ref-Bessembinder\" class=\"reference\"><a href=\"#cite_note-Bessembinder\"><span>[</span>2<span>]</span></a></sup> (in a 2003 paper) recommends as follows:\n",
    "\n",
    "1.  Use the EMO technique in preference to the LR method to sign trades\n",
    "\n",
    "2.  Implement the EMO technique on the basis of contemporaneous rather\n",
    "    than earlier quotations\n",
    "\n",
    "3.  Use quotation midpoints in effect somewhat prior to the trade report\n",
    "    time as the benchmark quote when measuring effective bid-ask\n",
    "    spreads."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### TAQ data cleaning\n",
    "\n",
    "Data cleaning is critical. Here follows a recipe for TAQ cleaning due to\n",
    "[Barndorff-Nielsen et al.]<sup id=\"cite_ref-BNS\" class=\"reference\"><a href=\"#cite_note-BNS\"><span>[</span>1<span>]</span></a></sup> and implemented in the R-package <span>highfrequency</span>:\n",
    "\n",
    "<span>**All data**</span>\n",
    "\n",
    "- Delete entries with a timestamp outside the 9:30am–4pm window when the exchange is open.\n",
    "- Delete entries with a bid, ask or transaction price equal to zero.\n",
    "- Retain entries originating from a single exchange (NYSE in our application). Delete other entries.\n",
    "\n",
    "<span>**Quote data only**</span>\n",
    "\n",
    "- When multiple quotes have the same time stamp, we replace all these with a single entry with the median bid and median ask price.\n",
    "- Delete entries for which the spread is negative.\n",
    "- Delete entries for which the spread is more that 50 times the median spread on that day.\n",
    "- Delete entries for which the mid-quote deviated by more than 10 mean absolute deviations from a rolling centered median (excluding the observation under consideration) of 50 observations (25 observations before and 25 after).\n",
    "\n",
    "<span>**Trade data only**</span>\n",
    "\n",
    "- Delete entries with corrected trades. (Trades with a Correction Indicator, CORR $\\neq$ 0).\n",
    "- Delete entries with abnormal Sale Condition. (Trades where COND has a letter code, except for E and F). See the TAQ 3 Users Guide for additional details about sale conditions.\n",
    "- If multiple transactions have the same time stamp, use the median price.\n",
    "- Delete entries with prices that are above the ask plus the bid–ask spread. Similar for entries with prices below the bid minus the bid–ask spread.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Autocorrelation of BAC trade signs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false,
    "slideshow": {
     "slide_type": "-"
    }
   },
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U1Nd3e3R52B0NDQF1988ciRI21t\nbS+99NLEiRMNBoNHnYFXX331iy++qKioKC4u9vb2rqiomDBhgo7PgLt/SjkgSktLb7/99pCQkLS0\ntPb2dncvR7aoqKieV3E4POls/OIXv+j17X327FmHJ50Bu93+3HPPjRo1KiAgYMaMGUeOHHGOe84Z\n6HH27NmeV3E4dHsG+MB+AFDUILzFAQCDA4EGAEURaABQFIEGAEURaABQFIEGAEURaABQFIEGAEUR\naABQFIEGAEURaABQFIEGAEURaABQFIEGAEURaABQFIEGAEURaABQFIEGAEURaABQFIHGoNXW1ubl\n5dXU1OTuhQDXiUADgKIINDzOn/70p9GjR5b5NSsAAAIBSURBVPv7+0+aNOno0aPOwXXr1sXGxsbG\nxubn58fGxrp1gcA3CDQ8S2Nj4/Lly994442TJ0+OHTt2zZo1QojKyspnnnnm7bff/vjjj3Nzc929\nRuAbBBqexWg0VlVV3XvvvUajMTIy8ty5c0KIt956Ky0t7c4774yKilq1apW71wh8w9fdCwCkMhgM\nBQUFZrPZx8fHYDCEhYUJIerq6u68807nE2JiYty6QODfuIKGZ3nnnXfefffdrVu37t27Ny0tzTkY\nHh5eW1vr/PrUqVNuWxxwOa6gMcidP3/e1/eb73N/f/+GhgY/Pz8vL6+SkpJXXnklODi4u7vbZDLN\nnDnz0UcfjYqKeumll9y7YKAHV9AY5MaMGRP0L3//+98XLVrk7+8fExOzcuXKF1544ciRI2+++WZi\nYmJWVlZqauqUKVMyMjKMRqO7Vw0IwRU0BrGAgACHw3Hl+J49e3q+rqmpEUKcOHFi8uTJ9fX1Qoiy\nsrKRI0fKWiNwNVxBA+LEiROPPPLI6dOnOzo6Vq9e/cADD7h7RYAQBBoQQkyZMmXRokUTJkyIiYnx\n8/NbunSpu1cECCGEl+b/AwIA3I4raABQFIEGAEURaABQFIEGAEURaABQFIEGAEURaABQFIEGAEUR\naABQFIEGAEURaABQFIEGAEURaABQFIEGAEURaABQ1P8DuBc6ijyuqxwAAAAASUVORK5CYII=\n"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%%R\n",
    "\n",
    "load(\"tq.rData\")\n",
    "tqdata <- tqBAC\n",
    "\n",
    "# Compute trade signs\n",
    "tradeSigns <- getTradeDirection(tqdata) \n",
    "\n",
    "# Autocorrelation of trade signs\n",
    "acTS <- acf(tradeSigns,main=NA,plot=FALSE)\n",
    "plot(acTS,main=NA,col=\"red\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 4: Autocorrelation of trade signs (04-May-2012)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Estimate of Roll model using trade signs\n",
    "\n",
    "-   Recall the Roll model: $$p_t=m_{t}+c\\,\\epsilon_t.$$\n",
    "\n",
    "\n",
    "-   The Roll half-spread estimate just from trade data was $0.295$\n",
    "    cents.\n",
    "\n",
    "\n",
    "-   Now that we have trade signs, we may use these to estimate the\n",
    "    half-spread from the regression\n",
    "    $$\\Delta p_t=\\Delta m_t+c\\,(\\epsilon_t-\\epsilon_{t-1})$$ The\n",
    "    resulting estimate of the half-spread in this case is $0.264$ cents.\n",
    "\n",
    "\n",
    "-   Only the first order autocorrelation coefficient of price changes is\n",
    "    significant, consistent with the Roll model.\n",
    "\n",
    "\n",
    "-   Trade signs are very autocorrelated with all coefficients\n",
    "    significant.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### A generalization of the Roll model\n",
    "\n",
    "-   As before, we model trade prices $p_t$ as\n",
    "    $$p_t=m_{t}+c\\,\\epsilon_t$$ but we allow the evolution of the\n",
    "    efficient price to depend on the trade sign:\n",
    "    \n",
    "    <a name=\"eq:GRoll\"></a>(2)\n",
    "    $$\\Delta m_t=m_t-m_{t-1}=\\lambda\\,\\epsilon_t+u_t$$\n",
    "\n",
    "    with $\\mbox{Cov}[\\epsilon_t,u_t]=0$.\n",
    "\n",
    "    -   This could reflect market impact and/or asymmetric information.\n",
    "\n",
    "\n",
    "-   Autocovariances are:\n",
    "\n",
    "    \\begin{eqnarray*}\n",
    "    \\gamma_0&=&\\mathbb{E} [\\Delta p^2]=c^2+(c+\\lambda)^2+\\sigma_u^2\\\\\n",
    "    \\gamma_1&=&\\mathbb{E} [\\Delta p_t\\, \\Delta p_{t-1}]=-c\\,(c+\\lambda)\\end{eqnarray*}\n",
    "\n",
    "\n",
    "-   All higher order autocovariances are zero.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Estimation of parameters\n",
    "\n",
    "-   The variance of the efficient price is given by\n",
    "    $$\\mbox{Var}[\\Delta m_t]=\\lambda^2+\\sigma_u^2=\\gamma_0+2\\,\\gamma_1$$\n",
    "\n",
    "\n",
    "-   Thus $\\gamma_0$ and $\\gamma_1$ are not sufficient to identify $c$\n",
    "    and $\\lambda$ separately.\n",
    "\n",
    "\n",
    "-   With synchronized quotes or alternatively trade sign data, we can\n",
    "    identify $\\lambda$ and $c$ separately by regression. <br>\n",
    "    (Recall that $\\Delta p_t = (\\lambda + c)\\epsilon_t - c\\epsilon_{t-1} + u_t$)\n",
    "\n",
    "    -   With our BAC data, we get $\\lambda = 0.054$ cents and\n",
    "        $c = 0.234$ cents.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Empirical notions of spread\n",
    "\n",
    "-   <span>**The effective spread**</span>\n",
    "    $$s^E=\\langle  2\\,\\epsilon_t\\,(p_t-m_t)  \\rangle$$\n",
    "\n",
    "\n",
    "-   <span>**The realized spread**</span>\n",
    "    $$s^R=\\langle  2\\,\\epsilon_t\\,(p_t-m_{t+\\tau})  \\rangle$$ for some\n",
    "    $\\tau >0$ (5 minutes say).\n",
    "\n",
    "\n",
    "-   In the Roll model, the two notions of spread coincide but if trading\n",
    "    affects the mid-price, the two notions will not in general agree.\n",
    "\n",
    "    -   Note that we don’t need to believe in asymmetric information to\n",
    "        believe in market impact. Recall that there is market impact in\n",
    "        the zero-intelligence model.\n",
    "\n",
    "\n",
    "-   In general, empirically, the realized spread is smaller than the\n",
    "    effective spread.\n",
    "\n",
    "    -   With our BAC data, the effective spread is $0.283$ cents and\n",
    "        the realized spread after 500 trades is $0.146$ cents.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### BAC realized spread over time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "%%R\n",
    "\n",
    "mids <- (as.numeric(tqdata$OFR) + as.numeric(tqdata$BID))/2\n",
    "\n",
    "# Realized spread\n",
    "n <- length(p)\n",
    "rs <- function(lag){mean(tradeSigns[1:(n-lag)]*(p[1:(n-lag)]-mids[-(1:lag)]))}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.00146451]])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%R data.frame(rs(500))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAeAAAAHgCAIAAADytinCAAAgAElEQVR4nO3deVxU9d4H8A/rgICA\noIiKLApCFzUFDRdEhdwCREWhTMUFxaXSSq0s9VZPZWndLMtCr5HeXLIick8NxYKQRMkaFUVlUWRx\nAxURZp4/hhRwRGGYc87MfN5/PK+Z48z5fs/j6348nfktRkqlEkREJD3GYjdARETqMaCJiCSKAU1E\nJFEMaCIiiWJAExFJFAOaiEiiGNBERBLFgCYikigGNBGRRDGgiYgkig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PqqoqsTsiUo8BTQZn48aNCQkJ0dHR586dy8vL\nMzExEbsjIvVMxW6ASGgxMTGtW7c2NTV1dXUVuxeihvAOmgxO69atAdy8eRMAn2+QlDGgyUDduHHj\nu+++W716tdiNED0QA5oM1KhRo+Li4nx8fMRuhOiBjJRKpdg9EBGRGryDJiKSKAY0EZFEMaCJiCSK\nAU1EJFEMaCIiiWJAExFJFAOaiEiiGNBERBLFgCYikigGNBGRRDGgiYgkigFNRCRRDGgiIoliQBMR\nSRQDmohIohjQREQSxYAmIpIoBjQRkUT9P8iLwucjsF6qAAAAAElFTkSuQmCC\n"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%%R \n",
    "rsLag <- sapply(1:500,rs)\n",
    "plot(1:500,rsLag,col=\"red\",type=\"l\",xlab=expression(tau), ylab = \"Realized spread\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Figure 5: Realized BAC spread vs number of trades after execution (04-May-2012)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### BAC realized spread by reporting exchange\n",
    "\n",
    "\n",
    "<h2><img src=\"http://mfe.baruch.cuny.edu/wp-content/uploads/2015/02/realizedSpreadByExch.png\" align = \"center\" width=550></h2>\n",
    "\n",
    "Figure 6: Different exchanges have different realized spread profiles depending on fee structure."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Determinants of the bid-ask spread\n",
    "\n",
    "Recall that there are three main determinants of the bid-ask spread:\n",
    "\n",
    "-   Processing costs (which include the profit of the market maker)\n",
    "\n",
    "-   Inventory costs such as cost of risk capital\n",
    "\n",
    "-   Adverse selection\n",
    "\n",
    "In the Roll model, only processing costs are taken into account. In the\n",
    "generalized Roll model, adverse selection is also taken into account.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Models with asymmetric information\n",
    "\n",
    "There are two main classes of model with asymmetric information:\n",
    "\n",
    "-   Strategic trader models where typically a single informed trader\n",
    "    optimizes his use of information.\n",
    "\n",
    "    -   A good example is the Kyle model which we will cover in the next\n",
    "        lecture.\n",
    "\n",
    "\n",
    "-   Sequential trader models where randomly selected traders arrive one\n",
    "    after the other, independently.\n",
    "\n",
    "    -   The prototypical example is Glosten and Milgrom (1985).\n",
    "\n",
    "\n",
    "-   In sequential trader models, the spread set by the market maker\n",
    "    compensates for adverse selection.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### A sequential trade model (Glosten and Milgrom)\n",
    "\n",
    "-   In the Glosten and Milgrom model, the market maker $\\mathcal{M}$\n",
    "    learns the informed trader $\\mathcal{I} $’s information by observing\n",
    "    the order flow.\n",
    "\n",
    "    -   If there are more buys than sells over time, $\\mathcal{M}$ sets\n",
    "        the price higher.\n",
    "\n",
    "-   $\\mathcal{M}$ posts bid and ask prices $B$ and $A$.\n",
    "\n",
    "-   The value of the security is either high ($\\bar V$) with probability\n",
    "    $\\delta$ or low ($\\underbar V$).\n",
    "\n",
    "-   A trader is drawn at random: either informed $\\mathcal{I} $ with\n",
    "    probability $\\mu$ or uninformed $\\mathcal{U}$.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Sequential trade model event tree\n",
    "\n",
    "<a name=\"eq:GlostenMilgromTree\"></a>(3)\n",
    "\n",
    "<h2><img src=\"http://mfe.baruch.cuny.edu/wp-content/uploads/2015/02/sequentialModelEventTree.png\" align = \"center\" width=500></h2>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Unconditional probabilities\n",
    "\n",
    "The unconditional probability of a buy is given by\n",
    "\n",
    "\\begin{eqnarray*}\n",
    "\\Pr[Buy]=\\frac{1}{2}\\,\\left(1-\\mu\\right)+\\delta\\,\\mu=\\frac 12 \\,\\left\\{1-\\mu\\,(1-2\\,\\delta)\\right\\}.\\end{eqnarray*}\n",
    "\n",
    "Similarly, the unconditional probability of a sell is given by\n",
    "\n",
    "$$\\Pr[Sell]=\\frac{1}{2} \\,(1-\\mu)+(1-\\delta)\\,\\mu=\\frac 12 \\,\\left\\{1+\\mu\\,(1-2\\,\\delta)\\right\\}.$$\n",
    "\n",
    "If $\\delta = \\frac12$, $\\Pr[Buy] = \\Pr[Sell] = \\frac12$.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Optimal bid price\n",
    "\n",
    "Under <span>*perfect competition*</span>, the optimal ask price is set\n",
    "as\n",
    "\n",
    "\\begin{eqnarray*}\n",
    "A&=&\\mathbb{E} [V|Buy]\\\\\n",
    "&=&{\\bar V\\,\\Pr(\\bar V|Buy)+\\underbar V\\,\\Pr(\\underbar V|Buy)}\\\\\n",
    "&=&\\frac{\\bar V\\,\\Pr(\\bar V \\cap Buy)+\\underbar V\\,\\Pr(\\underbar V \\cap Buy)}{\\Pr(Buy)}\\end{eqnarray*}\n",
    "\n",
    "By inspection of the Glosten and Milgrom tree [(3)](#eq:GlostenMilgromTree), we have\n",
    "\n",
    "\\begin{eqnarray*}\n",
    "\\Pr(\\bar V \\cap Buy) &=& \\delta\\,\\left\\{\\mu+\\frac 12 (1-\\mu)\\right\\} = \\frac12 \\delta (1 + \\mu) \\\\\n",
    "\\Pr(\\underbar V \\cap Buy) &=& (1-\\delta)\\,\\left\\{0+\\frac 12 (1-\\mu)\\right\\} = \\frac12 (1 - \\delta)(1 - \\mu)\n",
    "\\end{eqnarray*}\n",
    "\n",
    "and we already computed that\n",
    "$\\Pr(Buy)=\\frac 12 \\,\\left\\{1-\\mu\\,(1-2\\,\\delta)\\right\\}$. So\n",
    "\n",
    "$$A=\\mathbb{E} [V|Buy]=\\frac{\\underbar V\\,(1-\\delta)\\,(1-\\mu)+\\bar V\\,\\delta\\,(1+\\mu)}{1-\\mu\\,(1-2\\,\\delta)}.$$\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### The spread\n",
    "\n",
    "Similarly,\n",
    "\n",
    "$$B=\\mathbb{E} [V|Sell]=\\frac{\\underbar V\\,(1-\\delta)\\,(1+\\mu)+\\bar V\\,\\delta\\,(1-\\mu)}{1+\\mu\\,(1-2\\,\\delta)}$$\n",
    "\n",
    "so the spread is\n",
    "\n",
    "$$s=A-B=\\frac{4\\,(\\bar V-\\underbar V)\\,\\mu\\,\\delta\\,(1-\\delta)}{1-\\mu^2\\,(1-2\\,\\delta)^2}.$$\n",
    "\n",
    "When $\\delta=1/2$, \n",
    "\n",
    "$$s=\\mu\\,(\\bar V-\\underbar V)$$ \n",
    "\n",
    "and in this case, the spread is proportional to the probability of informed trading.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Observations\n",
    "\n",
    "-   The mid-price equals the fair price\n",
    "    $\\mathbb{E} [V]=\\delta \\,\\underbar V+(1-\\delta)\\,\\bar V$ only when\n",
    "    $\\delta=1/2$.\n",
    "\n",
    "    -   The bid and ask prices are not set around symmetrically around\n",
    "        the efficient price.\n",
    "\n",
    "\n",
    "-   The maximum spread is at $\\delta=1/2$ when uncertainty on $V$ is\n",
    "    maximized. The closer $\\delta$ is to $1$ or $0$, the smaller the\n",
    "    spread.\n",
    "\n",
    "\n",
    "-   As the probability of informed trading $\\mu \\to 1$,\n",
    "    $B \\to \\underbar V$ and $A \\to \\bar V$.\n",
    "\n",
    "\n",
    "-   The more informed trading is, the wider the spread. In the limit\n",
    "    where for example insider trading is allowed, we may see $\\mu=1$ and\n",
    "    subsequently market failure with no dealer willing to post quotes.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Model dynamics\n",
    "\n",
    "-   The dealer now updates his belief about the efficient price by\n",
    "    taking the sign of the previous trade into account.\n",
    "\n",
    "Let $\\delta_k=\\Pr(\\bar V|\\delta_{k-1},\\epsilon_{k-1})$ where $\\epsilon_i$ denotes the sign of the $i$th trade.\n",
    "\n",
    "Then if $\\epsilon_{k-1}=+1$,\n",
    "\n",
    "$$\\delta_k=\\frac{\\Pr(\\bar V\\cap(\\epsilon_{k-1}=+1)|\\delta_{k-1})}{\\Pr(\\epsilon_{k-1}=+1|\\delta_{k-1})}=\\frac{(1+\\mu)\\,\\delta_{k-1}}{1-\\mu\\,(1-2\\,\\delta_{k-1})}.$$\n",
    "\n",
    "and if $\\epsilon_{k-1}=-1$,\n",
    "\n",
    "$$\\delta_k=\\frac{(1-\\mu)\\,\\delta_{k-1}}{1+\\mu\\,(1-2\\,\\delta_{k-1})}.$$\n",
    "\n",
    "This may be summarized as:\n",
    "\n",
    "<a name=\"eq:GMupdate\"></a>(4)\n",
    "$$\\delta_k=\\frac{(1+\\mu\\,\\epsilon_{k-1})\\,\\delta_{k-1}}{1-\\mu\\,\\epsilon_{k-1}\\,(1-2\\,\\delta_{k-1})}.$$\n",
    "\n",
    "Thus, $\\delta_k$ may be computed recursively from the time series\n",
    "$\\{\\epsilon_i:i<k\\}=:\\mathcal{F} _k$ and $\\delta_0$.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Dynamical properties of the model\n",
    "\n",
    "-   The trade price series is a martingale.\n",
    "\n",
    "    -   Both bid and ask prices are expectations conditioned on an\n",
    "        expanding information set (the time series of trade signs):\n",
    "\n",
    "        \\begin{eqnarray*}\n",
    "        B_k&=&\\mathbb{E} [V|\\mathcal{F} _k,\\epsilon_k=-1] \\\\\n",
    "        A_k&=&\\mathbb{E} [V|\\mathcal{F} _k,\\epsilon_k=+1]\\end{eqnarray*}\n",
    "\n",
    "\n",
    "-   Order signs are predictable:\n",
    "    $\\mathbb{E} [\\epsilon_k|\\mathcal{F} _k] \\neq 0$ in general.\n",
    "\n",
    "\n",
    "-   The spread declines over time. Trading reveals the efficient price.\n",
    "\n",
    "\n",
    "-   Orders are serially correlated because informed traders always trade\n",
    "    in the same direction.\n",
    "\n",
    "\n",
    "-   There is market impact in this model. A buy causes both the bid and\n",
    "    the offer to increase.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Further observations\n",
    "\n",
    "-   If processing costs are $c$, the bid decreases by $c$ and the ask\n",
    "    increases by $c$.\n",
    "\n",
    "    -   Bid and ask prices are still martingales but the time series of\n",
    "        trade prices is no longer a martingale.\n",
    "\n",
    "\n",
    "-   From the Roll model perspective, information asymmetry has broken\n",
    "    the independence between the trade signs $\\epsilon_i$ and the\n",
    "    innovation to the efficient price.\n",
    "\n",
    "\n",
    "-   It is implicit that there is no risk aversion and unlimited capital\n",
    "    in the Glosten and Milgrom model so there is no inventory component\n",
    "    to the bid and ask prices.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Market efficiency\n",
    "\n",
    "According to the classical definitions, prices are\n",
    "\n",
    "-   <span>*strong-form efficient*</span> if they reflect all private\n",
    "    information\n",
    "\n",
    "-   <span>*semi-strong-form efficient*</span> if they reflect all public\n",
    "    information\n",
    "\n",
    "-   <span>*weak-form efficient*</span> if they reflect all information\n",
    "    in their past values.\n",
    "\n",
    "In the Glosten and Milgrom model, prices converge to the true value\n",
    "eventually becoming strong-form efficient. However at any given time, as\n",
    "a martingale reflecting all information available to the market maker,\n",
    "the price is only semi-strong-form efficient,\n",
    "\n",
    "-   Note that prices can depart substantially from the true value,\n",
    "    depending on order flow. So it’s not clear how interesting it is to\n",
    "    know that the market price is semi-strong-form efficient.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### The Foucault (1999) model\n",
    "\n",
    "-   <span>Trading starts at time $t=1$ and ends at $t=T$ where $T$ is a\n",
    "    random stopping time.</span>\n",
    "\n",
    "    -   At each time $t$, the probability that trading will terminate is\n",
    "        $1-\\rho$.\n",
    "\n",
    "\n",
    "-   If trading terminates, the payoff is\n",
    "    $$V_T=v_0+\\sum_{t=1}^T\\,\\epsilon_t$$ where $\\epsilon_t$ is an iid sequence of random variables with $\\epsilon_t=\\pm \\sigma$\n",
    "    with probability $1/2$.\n",
    "\n",
    "\n",
    "-   At each $t$, a trader arrives with a private valuation (or\n",
    "    <span>*reservation*</span>) price $R_t=v_t +y_t$ with $y_t=\\pm L$\n",
    "    (plus sign biases towards buying).\n",
    "\n",
    "    -   <span>This trader may either submit a market order or quote a\n",
    "        two-way price.</span>\n",
    "\n",
    "\n",
    "-   <span>Limit orders expire after one period so at any time $t$ either\n",
    "    the book is empty or it has one share on each side posted by the\n",
    "    trader\n",
    "    arriving at $t-1$.</span>\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Bid and ask prices under perfect competition\n",
    "\n",
    "Assuming perfect competition, the trader will set bid and offer prices\n",
    "so that he has zero utility at time $t+1$:\n",
    "\n",
    "\\begin{eqnarray*}\n",
    "\\mathbb{E} [V_T+y_t|\\text{Bid hit}]-B&=&0\\\\\n",
    "A-\\mathbb{E} [V_T+y_t|\\text{Offer lifted}]&=&0\\end{eqnarray*}\n",
    "\n",
    "and $\\mathbb{E}[V_T|v_{t+1}]=v_{t+1}$ so\n",
    "\n",
    "\\begin{eqnarray*}\n",
    "B&=&R_t+\\mathbb{E} [\\Delta v_{t+1}|\\text{Bid hit}]\\\\\n",
    "A&=&R_t+\\mathbb{E} [\\Delta v_{t+1}|\\text{Offer lifted}]\\end{eqnarray*}\n",
    "\n",
    "The time $t$ trader knows the statistics of the process $v_t$ and can\n",
    "compute the probabilities of execution at $B$ and $A$.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### A generic timestep in the Foucault model\n",
    "\n",
    "<h2><img src=\"http://mfe.baruch.cuny.edu/wp-content/uploads/2015/02/FoucaulStep.png\" align = \"center\" width=550></h2>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Computing the optimal bid price $B$\n",
    "\n",
    "Consider the bid price $B$:\n",
    "\n",
    "-   As $B$ increases, the probability of execution increases because MS\n",
    "    payoffs increase.\n",
    "\n",
    "-   As $B$ increases, the market maker’s payoff decreases.\n",
    "\n",
    "At some point, the expected market maker payoff will be zero and that\n",
    "will be the equilibrium level of $B$.\n",
    "\n",
    "To proceed, we assume that $\\sigma > {3 \\,L}/{2}$.\n",
    "\n",
    "-   It is nearly always the case in practice that the signal is smaller\n",
    "    than the noise!\n",
    "\n",
    "-   Even in the ZI market studied in HW1, the standard deviation of the\n",
    "    final price after 100 events was much greater than the mean price.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Computing the equilibrium bid price $B$\n",
    "\n",
    "We can use the tree diagram to compute the conditional expectations of\n",
    "$\\Delta v$. Wlog, we set $v_t=0$ and consider the case of a trader with\n",
    "private valuation $+L$. We denote the probability of the trader’s bid\n",
    "being hit conditional on $B$ by $\\mathbb{P} (\\text{hit}|B)$.\n",
    "\n",
    "\n",
    "|Bid price range$\\text{}~~~$   | $\\mathbb{P}$(hit$|B$)  | $\\mathbb{E}$[$\\Delta v_{t+1}$$|$Bid hit]  |  Breakeven $B$ |\n",
    "|------------------|------------------------|-------------------------------------------|----------------|\n",
    "| $>L+\\sigma$  | $\\rho$  |  0 |  $L$ |\n",
    "| $\\in (\\sigma-L,L+\\sigma]$  | $\\frac{3}{4}\\rho$  | $-\\sigma/3$  | $L-\\sigma/3$  |\n",
    "| $\\in (L-\\sigma,\\sigma-L]$  |  $\\frac{1}{2}\\rho$ | $-\\sigma$  | $L-\\sigma$  |\n",
    "| <font color=\"red\">$\\leq L-\\sigma$</font>  |  $\\frac{1}{4}\\rho$ |  $-\\sigma$ | <font color=\"red\">$L-\\sigma$</font>  |\n",
    "\n",
    "Only on the fourth line do we see a match between the bid price range in\n",
    "the first column and the breakeven bid price (from perfect competition)\n",
    "in the last column. The equilibrium bid price for a trader with private\n",
    "valuation $+L$ is thus $+L-\\sigma$."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Summary and conclusions\n",
    "\n",
    "-   The equilibrium solution of the Foucault (1999) model (assuming\n",
    "    $\\sigma > {3\\,L}/2$) has the form\n",
    "    $$\\{B,A\\}= \\pm L +\\{-\\sigma,+\\sigma\\}$$ so the spread $A-B$ is\n",
    "    always $2\\,\\sigma$.\n",
    "\n",
    "    -   $s/2=\\sigma$: “The half-spread equals volatility per trade”.\n",
    "\n",
    "\n",
    "-   Bids and offers are biased according to the private valuation of the\n",
    "    market maker.\n",
    "\n",
    "\n",
    "-   The bid-offer spread compensates for adverse selection.\n",
    "\n",
    "    -   Our bid is hit when the price is falling - against us!\n",
    "\n",
    "    -   Our bid is not hit when the price is rising - against us again!\n",
    "\n",
    "    -   Higher volatility means greater adverse selection which is\n",
    "        compensated by a wider spread.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Wyart et. al.\n",
    "\n",
    "<h2><img src=\"http://mfe.baruch.cuny.edu/wp-content/uploads/2015/02/WyartPictures.png\" align = \"center\" width=600></h2>\n",
    "\n",
    "Figure 7: Graphs showing that spread is proportional to volatility in real markets"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Wyart et. al.\n",
    "\n",
    "[Wyart et al.]<sup id=\"cite_ref-WyartEtAl\" class=\"reference\"><a href=\"#cite_note-WyartEtAl\"><span>[</span>8<span>]</span></a></sup> find that\n",
    "\n",
    "-   <span>$s \\approx 1.58 \\sigma$ for the Paris Stock Exchange in\n",
    "    2002.</span>\n",
    "\n",
    "-   <span>$s \\approx 1.32 \\sigma$ for the NYSE in 2005.</span>\n",
    "\n",
    "[Wyart et al.]<sup id=\"cite_ref-WyartEtAl\" class=\"reference\"><a href=\"#cite_note-WyartEtAl\"><span>[</span>8<span>]</span></a></sup>, show that the following assumptions imply proportionality of\n",
    "volatility per trade and spread:\n",
    "\n",
    "1.  Diffusion of market prices (<span>*i.e.*</span>\n",
    "    $\\langle (S_\\tau-S_0)^2\\rangle \\propto \\tau $).\n",
    "\n",
    "2.  The costs of market orders and limit orders are roughly equal.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Strategic uninformed trading\n",
    "\n",
    "-   It is possible for an uninformed trader to push up the price by\n",
    "    buying.\n",
    "\n",
    "    -   Is market manipulation possible in this model?\n",
    "\n",
    "    -   It certainly would be better for the uninformed trader to trade\n",
    "        strategically.\n",
    "\n",
    "\n",
    "-   For everyone except the actual buyer, the expectation of the\n",
    "    efficient price increases after a trade.\n",
    "\n",
    "    -   However, the expectation of the trader himself cannot change. He\n",
    "        has no more information after the trade than he had before.\n",
    "\n",
    "\n",
    "-   Sequential trader models are thus fundamentally unrealistic as\n",
    "    uninformed traders never learn and cannot behave strategically.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Further extensions of the Roll model\n",
    "\n",
    "-   Sequential trader models suggest how private information may get\n",
    "    impounded into the price.\n",
    "\n",
    "    -   The spread must include a component that compensates for adverse\n",
    "        selection.\n",
    "\n",
    "\n",
    "-   We now proceed to further extend the Roll model to investigate\n",
    "    empirically the components of the bid-ask spread.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### The Glosten and Harris model\n",
    "\n",
    "-   Order processing costs and adverse selection costs are allowed to\n",
    "    depend on trade size.\n",
    "\n",
    "\n",
    "-   A simplified version of their dynamics is:\n",
    "\n",
    "    <a name=\"eq:GlostenHarris\"></a>(5)\n",
    "    $$p_t=m_t+c\\,\\epsilon_t+\\lambda\\,x_t$$\n",
    "    <a name=\"eq:GlostenHarris2\"></a>(6)\n",
    "    $$m_t=m_{t-1}+\\lambda\\,x_{t-1}+u_t$$\n",
    "\n",
    "    where $x_t$ is (signed) trade size and $\\lambda$ may be identified\n",
    "    with the Kyle lambda.\n",
    "\n",
    "\n",
    "-   The half-spread in this model is now given by\n",
    "    $$\\frac{s_t}{2}=c+\\lambda\\,|x_t|$$\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### The Glosten and Harris model\n",
    "\n",
    "-   Note that $p_t$ may be reexpressed as\n",
    "\n",
    "    <a name=\"eq:lambdaRegression\"></a>(7)\n",
    "    $$p_t=\\lambda\\,\\sum_{i \\leq t}\\,x_i+c\\,\\epsilon_t+\\sum_{i \\leq t} u_i.$$\n",
    "\n",
    "    Thus $\\lambda$ may be estimated by regressing the daily price change\n",
    "    against net order flow.\n",
    "\n",
    "\n",
    "-   The first term may be identified with permanent impact and the\n",
    "    second with temporary impact.\n",
    "\n",
    "\n",
    "-   Glosten and Harris estimated their model on NYSE stock data from\n",
    "    01-Dec-1981 to 31-Jan-1983 finding:\n",
    "\n",
    "    \\begin{eqnarray*}\n",
    "    c&=&4.44 \\text{ cents}\\\\\n",
    "    \\lambda &=& 1.13 \\text{ cents per 1,000 shares}\\end{eqnarray*}\n",
    "    \n",
    "\n",
    "-   From our BAC data, $c = 0.271$ cents, $\\lambda = 0.0009$ cents per\n",
    "    $1,000$ shares.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### The ILLIQ measure (using daily data)\n",
    "\n",
    "-   The net order flow $\\sum_i x_i$ is typically not easily available.\n",
    "\n",
    "\n",
    "-   This led Amihud to propose an alternative proxy for transactions\n",
    "    costs:\n",
    "    $$\\text{ILLIQ}=\\left\\langle \\frac{|\\Delta P_t|}{V_t}\\right\\rangle$$\n",
    "    where $V_t$ is the absolute volume traded on day $t$. $\\langle \\cdot \\rangle = $ sample mean.\n",
    "\n",
    "\n",
    "-   It turns out that ILLIQ has a higher rank correlation with effective\n",
    "    spread than the Roll estimator.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### The Madhavan Richardson and Roomans (MRR) model\n",
    "\n",
    "-   In the Glosten and Milgrom model, the price depends on order flow.\n",
    "\n",
    "\n",
    "-   In the MRR model, as in Glosten-Milgrom, the revision in beliefs is\n",
    "    positively correlated with the innovation in the order flow:\n",
    "\n",
    "    <a name=\"eq:MRRsurprise\"></a>(8)\n",
    "    $$\\Delta V_t=\\lambda\\,\\left(\\epsilon_t-\\mathbb{E} [\\epsilon_t|\\mathcal{F} _{t-1}]\\right)+e_t$$\n",
    "\n",
    "    where $V_t$ is the efficient price and $e_t$ represents for example\n",
    "    news.\n",
    "\n",
    "\n",
    "-   As in Glosten and Milgrom, the market maker posts bid and ask prices\n",
    "    that are conditioned on the trade being a buy or a sell.\n",
    "\n",
    "\n",
    "-   This leads to the empirical model\n",
    "\n",
    "    <a name=\"eq:MRRprice\"></a>(9)\n",
    "    $$p_t=V_t+\\phi\\,\\epsilon_t+\\xi_t$$\n",
    "\n",
    "    where $\\xi_t$ is iid noise that could represent rounding for\n",
    "    example."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Autocorrelation of order flow\n",
    "\n",
    "-   From [(8)](#eq:MRRsurprise) and [(9)](#eq:MRRprice),\n",
    "\n",
    "    <a name=\"eq:MRR3\"></a>(10)\n",
    "    $$p_t=V_{t-1}+\\lambda\\,\\left(\\epsilon_t-\\mathbb{E} [\\epsilon_t|\\mathcal{F}_{t-1}]\\right) + \\phi\\,\\epsilon_t + e_t+\\xi_t$$\n",
    "\n",
    "\n",
    "-   Let $\\gamma$ be the probability of a continuation (in trade sign)\n",
    "    $$\\gamma=\\Pr[\\epsilon_t=\\epsilon_{t-1}].$$\n",
    "\n",
    "\n",
    "-   Because of trade-splitting, continuations are more likely than\n",
    "    reversals so $\\gamma > 1/2$.\n",
    "\n",
    "\n",
    "-   The first order autocorrelation $\\rho_1$ of trade signs is then\n",
    "    $2\\,\\gamma-1$.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Expected trade sign\n",
    "\n",
    "-   Now model the order sign process as AR(1) so that\n",
    "    $$\\epsilon_t=\\rho\\,\\epsilon_{t-1}+\\eta_t$$ where $\\eta_t$ is\n",
    "    independent noise. Then\n",
    "    $ \\mathbb{E} [\\epsilon_t|\\epsilon_{t-1}]=\\rho\\,\\epsilon_{t-1}$.\n",
    "\n",
    "\n",
    "-   From [(8)](#eq:MRRsurprise) and [(9)](#eq:MRRprice) we then obtain\n",
    "\n",
    "    <a name=\"eq:MRRdynamics\"></a>(11)\n",
    "    $$\\Delta p_t=(\\phi+\\lambda)\\,\\epsilon_t-(\\phi+\\rho\\,\\lambda)\\,\\epsilon_{t-1}+e_t+\\Delta \\xi_t$$\n",
    "\n",
    "    which does not involve the fair price $V_t$ and may be estimated\n",
    "    from data.\n",
    "\n",
    "    -   Note here the assumption that autocorrelation coefficients of\n",
    "        order higher than one are zero.\n",
    "\n",
    "\n",
    "-   Thus, in this model, price changes reflect:\n",
    "\n",
    "    -   The unexpected component of order flow\n",
    "\n",
    "    -   News\n",
    "\n",
    "    -   Noise due to tick size and so on.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### MRR results\n",
    "\n",
    "<h2><img src=\"http://mfe.baruch.cuny.edu/wp-content/uploads/2015/02/MRR_Table2.png\" align = \"center\" width=550></h2>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Two quotes from MRR\n",
    "\n",
    "> The mean value of $\\theta$ (which we called $\\lambda$) falls by over a\n",
    "> third from the opening to the middle of the day (from 4.15 to 2.75\n",
    "> cents) and remains at this level until the final period where it\n",
    "> increases slightly.\n",
    "\n",
    "> The transaction cost element ($\\phi$) is approximately 3.4 cents in\n",
    "> the first half-hour and increases steadily over the day to 4.6 cents\n",
    "> in the final half-hour interval, a rise of about 30%.\n",
    "\n",
    "\n",
    "-   So, according to MRR, contributions from fixed costs and adverse\n",
    "    selection are roughly equal.\n",
    "\n",
    "    -   From our BAC data, $\\lambda = 0.059$ cents, $\\phi = 0.229$ cents\n",
    "        so nearly all of the effective spread is market maker profit.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### The Huang and Stoll model\n",
    "\n",
    "-   In this model, the unobservable efficient price is first modeled as\n",
    "\n",
    "    <a name=\"eq:HuangStoll1\"></a>(12)\n",
    "    $$V_t=V_{t-1}+\\alpha\\,\\frac{s}{2}\\,\\epsilon_{t-1}+e_t$$\n",
    "\n",
    "    where $s$ is the spread and $\\alpha$ is how much of the spread may\n",
    "    be attributed to informed trading (adverse selection).\n",
    "\n",
    "\n",
    "-   Also, according to the inventory model of Ho and Stoll, the\n",
    "    mid-price $m_t$ is given by\n",
    "\n",
    "    <a name=\"eq:HuangStoll2\"></a>(13)\n",
    "    $$m_t=V_t+\\beta\\,\\frac{s}{2}\\,\\sum_{i<t}\\,\\epsilon_i$$\n",
    "\n",
    "    so\n",
    "    $$\\Delta m_t = \\Delta  V_t +\\beta \\,\\frac{s}{2}\\,\\epsilon_{t-1}= (\\alpha+\\beta) \\,\\frac{s}{2}\\,\\epsilon_{t-1}+e_t$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Changes in trade price\n",
    "\n",
    "-   Now we assume $$p_t=m_t+\\frac{s}{2}\\,\\epsilon_t+\\xi_t$$\n",
    "\n",
    "\n",
    "-   This gives\n",
    "    $$\\Delta p_t =(\\alpha+\\beta) \\,\\frac{s}{2}\\,\\epsilon_{t-1}+\\frac{s}{2}\\,(\\epsilon_t-\\epsilon_{t-1})+e_t+\\Delta \\xi_t$$\n",
    "    which is amenable to estimation because it does not depend on\n",
    "    unobservables.\n",
    "\n",
    "    -   Note that the effects of $\\alpha$ and $\\beta$ cannot be\n",
    "        distinguished.\n",
    "\n",
    "\n",
    "-   The Roll model may be recovered by setting $\\alpha=\\beta=0$ to get\n",
    "    $$\\Delta p_t =\\frac{s}{2}\\,(\\epsilon_t-\\epsilon_{t-1})+\\eta_t$$ for\n",
    "    some noise $\\eta_t$.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Distinguishing adverse selection and inventory effects\n",
    "\n",
    "-   In inventory models, a change in the quote changes the arrival rate\n",
    "    of trades.\n",
    "\n",
    "    -   This induces negative serial covariance in mid-quotes, separate\n",
    "        from and in addition to the bid-ask bounce in $\\Delta p_t$.\n",
    "\n",
    "\n",
    "-   Let $\\pi$ be the probability of a reversal. Then\n",
    "    $$\\mathbb{E} [\\epsilon_{t-1}|\\epsilon_{t-2}]=(1-2\\,\\pi)\\,\\epsilon_{t-2}$$\n",
    "\n",
    "\n",
    "-   We modify [(12)](#eq:HuangStoll1) accordingly:\n",
    "\n",
    "    <a name=\"eq:HuangStoll22\"></a>(14)\n",
    "    \\begin{eqnarray*}\n",
    "    \\Delta V_t&=&\\alpha\\,\\frac{s}{2}\\,\\left(\\epsilon_{t-1}-\\mathbb{E} [\\epsilon_{t-1}|\\epsilon_{t-2}]\\right)+e_t\\nonumber\\\\\n",
    "    &=&\\alpha\\,\\frac{s}{2}\\,\\epsilon_{t-1}-\\alpha\\,\\frac{s}{2}\\,(1-2\\,\\pi)\\,\\epsilon_{t-2}+e_t\n",
    "    \\end{eqnarray*}\n",
    "\n",
    "\n",
    "-   Note that $$\\mathbb{E} [\\Delta V_t|V_{t-1},\\epsilon_{t-2}]=0$$\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Distinguishing adverse selection and inventory effects\n",
    "\n",
    "-   Combining [(13)](#eq:HuangStoll2) and [(14)](#eq:HuangStoll22) gives\n",
    "\n",
    "    <a name=\"eq:HuangStoll23\"></a>(15)\n",
    "    $$\\Delta m_t=(\\alpha+\\beta)\\,\\frac{s}{2}\\,\\epsilon_{t-1}-\\alpha\\,\\frac{s}{2}\\,(1-2\\,\\pi)\\,\\epsilon_{t-2}+e_t$$\n",
    "\n",
    "-   Note that what matters for inventory is not the unexpected portion\n",
    "    of the trade sign but the actual trade sign.\n",
    "\n",
    "-   Also, mid-quote changes are predictable:\n",
    "    $$\\mathbb{E} [\\Delta m_t|m_{t-1},\\epsilon_{t-2}]=\\beta\\,\\frac{s}{2}\\,(1-2\\,\\pi)\\,\\epsilon_{t-2}$$\n",
    "\n",
    "-   Equation [(15)](#eq:HuangStoll23) may be estimated directly or combined with [(13)](#eq:HuangStoll2) to give\n",
    "\n",
    "    <a name=\"eq:HuangStollPriceRegression\"></a>(16)\n",
    "    $$\\Delta p_t=\\frac{s}{2}\\,\\epsilon_t+(\\alpha+\\beta-1)\\,\\epsilon_{t-1}-\\alpha\\,\\frac{s}{2}\\,\\epsilon_{t-2}+e_t$$\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Comments\n",
    "\n",
    "-   Why stop at $\\epsilon_{t-2}$? The trade sign process is supposedly\n",
    "    long-memory and so all higher order autocovariances are positive.\n",
    "\n",
    "\n",
    "-   Equation [(14)](#eq:HuangStoll22) would then become\n",
    "    $$\\Delta V_t=\\alpha\\,\\frac{s}{2}\\,\\left(\\epsilon_{t-1}-\\mathbb{E} [\\epsilon_{t-1}|\\mathcal{F} _{t-1}]\\right)+e_t$$\n",
    "\n",
    "\n",
    "-   We could use any forecasting model we liked to compute\n",
    "    $\\mathbb{E} [\\epsilon_{t-1}|\\mathcal{F} _{t-1}]$.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Empirical results\n",
    "\n",
    "-   Huang and Stoll data is from all trading days in 1992.\n",
    "\n",
    "\n",
    "-   It is notable that the most highly traded stock in their sample is\n",
    "    MO with 751 trades per day.\n",
    "\n",
    "    -   1992 MO volume traded per day was around 5.6 million shares.\n",
    "\n",
    "    -   Recent MO volume traded per day is around 10 million shares over\n",
    "        roughly 35,000 trades. Times have changed!\n",
    "\n",
    "\n",
    "Quote from Huang and Stoll:\n",
    "\n",
    "> Under the adjusted results, the average order processing component of\n",
    "> the traded spread is 61.8%, the average adverse information component\n",
    "> is 9.6% ($\\alpha$), and the average inventory cost component ($\\beta$)\n",
    "> is 28.7%.\n",
    "\n",
    "With our BAC data, $\\frac s2 = 0.288$ cents, $\\alpha = 1.0\\%$,\n",
    "$\\beta = 17.9\\%$.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### The PIN model\n",
    "\n",
    "-   The Glosten and Milgrom model is extended to include the arrival of\n",
    "    news.\n",
    "\n",
    "-   Agents are not sequentially drawn in discrete time but arrive\n",
    "    randomly in continuous time. Events are modeled as Poisson\n",
    "    processes.\n",
    "\n",
    "    -   News arrives with intensity $\\alpha$. It is good news with\n",
    "        probability $\\delta$, bad news with probability $1-\\delta$.\n",
    "\n",
    "    -   Informed trades arrive with intensity $\\mu$.\n",
    "\n",
    "    -   Uninformed buys arrive with intensity $\\epsilon$.\n",
    "\n",
    "    -   Uninformed sells arrive with intensity $\\epsilon$.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### PIN model event tree\n",
    "\n",
    "<h2><img src=\"http://mfe.baruch.cuny.edu/wp-content/uploads/2015/02/PINEventTree.png\" align = \"center\" width=600></h2>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Unconditional arrival rates\n",
    "\n",
    "The total arrival rate of buy orders is given by\n",
    "\n",
    "$$\n",
    "\\lambda_{Buy} = \\alpha\\,  \\delta  \\,(\\epsilon +\\mu )+\\alpha \\, (1-\\delta )\\, \\epsilon +(1-\\alpha\n",
    "   )\\, \\epsilon = \\alpha\\,  \\delta\\,  \\mu +\\epsilon\n",
    "$$\n",
    "\n",
    "Similarly, the total arrival rate of sell orders is given by\n",
    "\n",
    "$$\\lambda_{Sell}=(1-\\delta)\\,  \\alpha\\,  \\mu +\\epsilon$$ \n",
    "\n",
    "and the total arrival rate by \n",
    "\n",
    "$$\\lambda=\\alpha\\,\\mu+2\\,\\epsilon.$$\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### PIN\n",
    "\n",
    "The *probability of informed trading* (PIN) is the unconditional probability\n",
    "that a randomly chosen trader on a randomly chosen day is informed:\n",
    "\n",
    "$$PIN=\\frac{\\alpha\\,\\mu}{\\alpha\\,\\mu+2\\,\\epsilon}$$\n",
    "\n",
    "-   PIN is estimated by maximum likelihood.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Maximum likelihood estimation of PIN\n",
    "\n",
    "-   Assume we can sign trades to give a sequence of buys and sells.\n",
    "\n",
    "-   The likelihood function is the relative probability of observing a\n",
    "    given number of buys and sells given the parameters\n",
    "    $\\psi=\\{\\alpha,\\delta, \\mu, \\epsilon\\}$ of the model.\n",
    "\n",
    "-   The probability of observing $n$ events in time $T$ when the\n",
    "    underlying process is Poisson with rate $\\lambda$ is\n",
    "    $$e^{-\\lambda\\,T}\\,\\frac{{(\\lambda\\,T)}^n}{n!}$$\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Maximum likelihood estimation of PIN\n",
    "\n",
    "-   We take $\\mu$ and $\\epsilon$ to be daily rates and consider the\n",
    "    number of buys $B$ and sells $S$ over one day.\n",
    "\n",
    "\n",
    "-   Then\n",
    "\n",
    "    \\begin{eqnarray*}\n",
    "    L(B,S;\\psi)&=&\\alpha\\,\\delta\\,e^{-(\\epsilon+\\mu)}\\,\\frac{(\\epsilon+\\mu)^B}{B!}\\,e^{-\\epsilon}\\,\\frac{\\epsilon^S}{S!}\n",
    "    + \\alpha\\,(1-\\delta)\\,e^{-\\epsilon}\\,\\frac{\\epsilon^B}{B!}\\,e^{-(\\epsilon+\\mu)}\\,\\frac{(\\epsilon+\\mu)^S}{S!}\n",
    "    + (1-\\alpha)\\,e^{-2\\,\\epsilon}\\,\\frac{\\epsilon^{B+S}}{B!\\,S!}\\end{eqnarray*}\n",
    "\n",
    "\n",
    "-   The parameters $\\psi$ are estimated by maximizing $L(B,S;\\psi)$.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Criticisms of PIN\n",
    "\n",
    "-   Every day is a new day: Each day’s trading is independent of the\n",
    "    previous day.\n",
    "\n",
    "-   Because of multiple trade reports, the trade-signing process itself\n",
    "    is suspect.\n",
    "\n",
    "-   News events occur at the start of trading.\n",
    "\n",
    "-   There are only two possible results, high and low.\n",
    "\n",
    "-   $\\alpha$ and $\\mu$ enter into PIN only through the product\n",
    "    $\\alpha\\,\\mu$: Estimates for $\\alpha$ and $\\mu$ separately are less\n",
    "    precise.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Interpretation of PIN\n",
    "\n",
    "-   Subsequent papers by Easley, O’Hara et al. have shown that PIN is an\n",
    "    explanatory variable for the cross-section of returns.\n",
    "\n",
    "    -   In fact, it can apparently replace momentum in the\n",
    "        Fama-French-plus-momentum factor model favored by for example\n",
    "        AQR.\n",
    "\n",
    "-   Perhaps because of this, PIN is used by equity long-short traders.\n",
    "\n",
    "-   Given the highly stylized assumptions, it’s not at all clear that\n",
    "    PIN measures informed trading. It does probably give a good\n",
    "    indication of order-flow one-sidedness (or momentum).\n",
    "\n",
    "    -   This is termed <span>*information risk*</span> by the authors.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Features of models studied so far\n",
    "\n",
    "-   The component of the bid-ask spread relating to order processing\n",
    "    costs is an immediate cost. This cost of trading is temporary and\n",
    "    has no price impact.\n",
    "\n",
    "-   The component of the bid-ask spread due to inventory effects has\n",
    "    temporary impact on the price that takes some time to dissipate.\n",
    "\n",
    "-   The component of the bid-ask spread due to information effects\n",
    "    (adverse selection) is permanent.\n",
    "\n",
    "    -   In the more sophisticated models, only the unexpected component\n",
    "        of order flow impacts the price.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Adverse selection\n",
    "\n",
    "-   In the traditional microstructure literature, adverse selection is\n",
    "    typically conflated with the effect of informed trading.\n",
    "\n",
    "-   Recall the quote from [Hasbrouck]<sup id=\"cite_ref-Hasbrouck\" class=\"reference\"><a href=\"#cite_note-Hasbrouck\"><span>[</span>5<span>]</span></a></sup>:\n",
    "\n",
    "    > Orders do not impact prices. It is more accurate to say that\n",
    "    > orders forecast prices.\n",
    "\n",
    "-   It could be that prices move because of the impact of orders, a\n",
    "    purely mechanical explanation.\n",
    "\n",
    "    -   It could be that the main information that traders have is the\n",
    "        ultimate size of their own order (or <span>*metaorder*</span>).\n",
    "        The market sees only the part of the metaorder that has already\n",
    "        been revealed.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### References\n",
    "\n",
    "<br />\n",
    "\n",
    "<div class=\"reflist\" style=\"list-style-type: decimal;\">\n",
    "\n",
    "<ol>\n",
    "\n",
    "  <li id=\"cite_note-BNS\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-BNS\">^</a></b></span>O.E Barndorff-Nielsen, P.R Hansen, A Lunde, N Shephard, Realized kernels\n",
    "in practice: Trades and quotes, <span>*Econometrics Journal*</span>\n",
    "<span>**12 (3)**</span> 1–32 (2009).\n",
    "  \n",
    "  </li>\n",
    "\n",
    "  <li id=\"cite_note-Bessembinder\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-Bessembinder\">^</a></b></span>Hendrik Bessembinder, Issues in assessing trade execution costs,\n",
    "<span>*Journal of Financial Markets*</span> <span>**6**</span>(3)\n",
    "233–257 (2003).\n",
    "  \n",
    "  </li>\n",
    "  \n",
    "  \n",
    "  <li id=\"cite_note-BouchaudFarmerLillo\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-BouchaudFarmerLillo\">^</a></b></span>Jean-Philippe Bouchaud, J. Doyne Farmer, and Fabrizio Lillo, How Markets\n",
    "Slowly Digest Changes in Supply and Demand, in <span>*Handbook of\n",
    "Financial Markets: Dynamics and Evolution*</span> 57-156. (2009)\n",
    "available at\n",
    "http://tuvalu.santafe.edu/%7Ejdf/papers/MarketsSlowlyDigest.pdf: Section\n",
    "7.\n",
    "  \n",
    "  </li>\n",
    "\n",
    "  <li id=\"cite_note-FPR\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-FPR\">^</a></b></span>Thierry Foucault, Marco Pagano and Ailsa Röell, <span>*Market\n",
    "Liqudity*</span>, Oxford University Press, Chapters 2 and 3. (2013).\n",
    "  \n",
    "  </li>\n",
    "  \n",
    "  \n",
    "  \n",
    "  <li id=\"cite_note-Hasbrouck\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-Hasbrouck\">^</a></b></span>Joel Hasbrouck, <span>*Empirical Market Microstructure*</span>, Oxford\n",
    "University Press, Chapters 5 and 6 (2007).\n",
    "  \n",
    "  </li>\n",
    "  \n",
    "  \n",
    "  <li id=\"cite_note-HuangStoll\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-HuangStoll\">^</a></b></span>Roger D. Huang and Hans R. Stoll, The components of the bid-ask spread:\n",
    "A general approach, <span>*Review of Financial Studies*</span>\n",
    "<span>**10**</span>(4) 995–1034 (1997).\n",
    "  \n",
    "  </li>\n",
    "  \n",
    "  \n",
    "  \n",
    "  <li id=\"cite_note-MRR\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-MRR\">^</a></b></span>Ananth Madhavan, Matthew Richardson, Mark Roomans, Why do security\n",
    "prices change? A transaction-level analysis of NYSE stocks,\n",
    "<span>*Review of Financial Studies*</span> <span>**10**</span>(4)\n",
    "1035–1064 (1997).\n",
    "  \n",
    "  </li>\n",
    "  \n",
    "  <li id=\"cite_note-WyartEtAl\"><span class=\"mw-cite-backlink\"><b><a href=\"#cite_ref-WyartEtAl\">^</a></b></span>Matthieu Wyart, Jean-Philippe Bouchaud, Julien Kockelkoren, Marc Potters\n",
    "and Michele Vettorazzo, Relation between bid-ask spread, impact and\n",
    "volatility in order-driven markets, <span>*Quantitative Finance*</span>\n",
    "<span>**8**</span>(1) 41–57 (2008).\n",
    "  \n",
    "  </li>\n",
    "  \n",
    "  \n",
    "</ol>"
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Slideshow",
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
